import cookie from "../cookie.js"
import cfg from "../config.js"


let page = {
    before_amis_embed: function(json){
        let crud_name=json.body[0].name;
        let datamodel=this.datamodel;
        let tablename=this.tablename;
        json.body[0].columns.push(
          {
              "type": "button",
              "tooltip":'发放',
              "icon":"fa fa-check-circle-o",
              "actionType":"ajax",
              "api":{
                  "method": "post",
                  "url": cfg.api_server + "datamodel/update",
                  "requestAdaptor": function (api) {
                    let rowDiff = {
                      id: api.data.id
                    };

                    if(api.data.wo_state!='开立')
                    {
                      alert("工单非开立状态，不允许释放!");
                    }
                    else
                    {
                      rowDiff["wo_state"] = "释放";
                    }
                    let row = api.data;
                    api.data = {
                      "rows": [row],
                      "rowsDiff": [rowDiff],
                      "rowsOrigin": [row]
                    }
                    api.data.datamodel = datamodel;
                    api.data.tablename = tablename;
                  
                  }
                }
          },
          {
            "type": "button",
            "icon":"fa fa-times-circle-o",
            "tooltip": "强制关闭",

            "actionType":"ajax",
            "api":{
                "method": "post",
                "url": cfg.api_server + "datamodel/update",
                "requestAdaptor": function (api) {
                  
                  let rowDiff = {
                    id: api.data.id
                  };
                    rowDiff["wo_state"] = "关闭";
                  
                  let row = api.data;
                  api.data = {
                    "rows": [row],
                    "rowsDiff": [rowDiff],
                    "rowsOrigin": [row]
                  }
                  api.data.datamodel = datamodel;
                  api.data.tablename = tablename;
                }
              }
        }
      );
    }
};

export default page;